/**
 * @Description
 */

public class MyQueue {

    static class Node {
        int val;
        Node next;
        public Node prev;

        public Node(int val) {
            this.val = val;
        }
    }

        public Node front;//队头
        public Node rear;//队尾

        //插入,相当于尾插法
        public void offer(int val){
            Node node = new Node(val);
            if(front==null){
                front = node;
                rear = node;
            }else{
                rear.next = node;
                node.prev = rear;
                rear = node;
            }
        }
        public int pull(){
            if(front==null){
                return -1;
            }
            int val = front.val;
            //防止只有一个节点
            if(front.next!=null){
                front = front.next;
                front.prev = null;
            }else{
                rear = null;
            }
            return val;
        }
        public int peek(){
            if(front==null){
                return -1;
            }
            return front.val;
        }
        public int size(Node head){
            Node cur = head;
            int count = 0;
            while(cur!=null){
                cur = cur.next;
                count++;
            }
            return count;
        }


}
